﻿using System.Collections.Generic;
using TrueSync;

namespace HEFramework
{
    public static class CampSystem
    {
        [EntitySystem]
        public class CampAwakeSystem : AwakeSystem<Camp, int, object>
        {
            protected override void Awake(Camp _self, int _a, object _b)
            {
                _self.MyID = _a;
                _self.Groups = _b as List<Camp.Group>;
            }
        }

        public static bool IsTeam(this Camp _self, int _a, int _b)
        {
            if (_a == _b)
            {
                return true;
            }

            return false;
        }

        public static bool IsFriend(this Camp _self, int _a, int _b)
        {
            if (_self.IsTeam(_a, _b))
            {
                return false;
            }

            for (int i = 0; i < _self.Groups.Count; i++)
            {
                var group = _self.Groups[i];
                int a = 0;
                int b = 0;
                for (int j = 0; j < group.Singles.Count; j++)
                {
                    var single = group.Singles[j];
                    if (single.ID == _a)
                    {
                        a = 1;
                    }

                    if (single.ID == _b)
                    {
                        b = 1;
                    }

                    if (a == 1 && b == 1)
                    {
                        return true;
                    }
                }
            }

            return false;
        }

        public static bool IsEnemy(this Camp _self, int _a, int _b)
        {
            if (_self.IsTeam(_a, _b))
            {
                return false;
            }

            if (_self.IsFriend(_a, _b))
            {
                return false;
            }

            return true;
        }
    }
}